<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - ExamResitTask" 
*/ 

component 
	displayname="public.service.db.senate.sequence.ExamResitTask" 
	output=false 
	accessors=true 
	{

	property type="string" name="TermID" hint="学期";
	property type="string" name="ExamResitIndex" hint="补考序号";
	
	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}
	
/**
	* @hint "生成补考序号"
	* 
	* @Term "学期"
	*/
	public string function getExamIDX() output=false {
		var sql = "";
		var queryObj = "";
		
		/* 
			考序号规则 6位代码
		*/
		var nextID = numberFormat(1, "0_____");
		
		sql = "SELECT a.rstidx 
				FROM t_resittask a  
				WHERE 
				a.term_id = :term 
				ORDER BY a.rstidx DESC";
		
		queryObj = new Query( datasource=application.dnsMaster,maxRows = 1);
		queryObj.addParam( name="term", value=getTermID(), cfsqltype="cf_sql_char" );
	
		var rs_check = queryObj.execute( sql=sql ).getResult();
			
		if (rs_check.recordCount) {
			/* 创建一个追加id */
			nextID = numberFormat((rs_check["rstidx"][1] + 1), "0_____");
		}

		return nextID;
	}
	
	/**
	* @hint "自定义主键规则"
	* 
	* @Term "学期"
	* @ExamResitIndex "补考序号"
	*/
	public string function getID() output=false {
		
		var nextID = getTermID() & "R" & getExamResitIndex();

		/* 
			主键生成规则 
			
			考试任务号10位 3位学期代码 1位考试类别代码[R-补考] 6位考序号

			Unique: TERM_ID, RSTIDX
		*/
		return nextID;
	}

}

</cfscript>